﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wsitech.BLL;
using Wsitech.Model;

public partial class Profession_Job : System.Web.UI.Page
{
    protected readonly string companyid = HttpContext.Current.Request["companyid"] ?? "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindPosition();
        }
    }

    //绑定职位信息
    private void bindPosition()
    {
        IList<PositionInfo> mainList = new List<PositionInfo>();
        IList<CompanyInfo> otherList = new List<CompanyInfo>();
        if (companyid == "")
        {
            mainList = PositionInfoBLL.Instance.GetActiveListByCompanyId(CompanyInfoBLL.COMPANY_LEGEND_ID);
            otherList = CompanyInfoBLL.Instance.GetActiveList();
        }
        else
        {
            CompanyInfo company = CompanyInfoBLL.Instance.GetDetail(companyid);
            if (company != null)
            {
                //公司名称
                lbCompanyName.Text = ">" + company.CompanyName;
                //公司简介
                panelDescription.InnerHtml = company.Description;
                //职位列表
                mainList = PositionInfoBLL.Instance.GetActiveListByCompanyId(companyid);
                //成员企业
                panelOther.Visible = false;
            }
        }
        //联想控股本公司信息
        repMain.DataSource = mainList;
        repMain.DataBind();

        //成员企业招聘信息
        //repOther.DataSource = otherList.Where(c => showCompany(c));
        //repOther.DataBind();
    }

    private bool showCompany(CompanyInfo company)
    {
        if (company.CompanyId == CompanyInfoBLL.COMPANY_LEGEND_ID)
        {
            return false;
        }
        if (!company.JobUrlEnabled && PositionInfoBLL.Instance.GetActiveListByCompanyId(company.CompanyId).Count == 0)
        {
            return false;
        }
        return true;
    }


    protected void repOther_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        CompanyInfo company = e.Item.DataItem as CompanyInfo;
        HyperLink hlEdit = (HyperLink)e.Item.FindControl("hlEdit");
        if (company != null)
        {
            if (company.JobUrlEnabled && company.JobUrl != "")
            {
                hlEdit.NavigateUrl = company.JobUrl;
            }
            else
            {
                hlEdit.NavigateUrl = string.Format("/Profession/Job.aspx?companyid={0}", company.CompanyId);
            }
        }
    }
}